﻿function DisplayHome(homeOrDetail) {

    $.getJSON("http://localhost:53425/api/KPI/jsonp?callback=?", function (data) {          //Get jsonp data, pass to function

        var indexOutput = '';                                                               //content container

        for (var i in data) {                                                              //iterate over jsonp objects

            var img = Images(data[i].currentValue, data[i].lastValue);                     //call image function

            var link = '<a href=\"';                                                       //Formats jQuery mobile Listview tiles and populates countainer with Jsonp data
            link += '#details';
            link += '\" onclick="DisplayDetails(' + data[i].iD + ');return false;">';

            indexOutput += "<li data-icon=\"false\">";                                      //Page 1 - tiles with summary for each kpi
            indexOutput += link;
            indexOutput += "<h1>" + data[i].name + "</h1>";
            indexOutput += "<h3>" + numberToCurrency(data[i].currentValue) + "</h3>";
            indexOutput += img;
            indexOutput += "</a></li>";
            indexOutput += "</ul>";
            indexOutput += "</li>";
        }

        var item = { text: "Awesome item" };
        client.getTable("Item").insert(item);

        

        $("#kpi").append(item);                                                         //send content to page, refresh listview as last task
        $("#kpi").listview('refresh');
    });

}